package com.example.text.ui.mall.adepter
//
//import android.content.Context
//import android.graphics.Bitmap
//import android.view.LayoutInflater
//import android.view.View
//import android.view.ViewGroup
//import android.widget.ImageView
//import androidx.recyclerview.widget.RecyclerView
//import com.bumptech.glide.load.DataSource
//import com.bumptech.glide.load.engine.GlideException
//import com.bumptech.glide.load.resource.bitmap.CenterCrop
//import com.bumptech.glide.load.resource.bitmap.RoundedCorners
//import com.bumptech.glide.request.RequestListener
//import com.bumptech.glide.request.RequestOptions
//import com.bumptech.glide.request.target.Target
//import com.example.text.R
//import com.example.text.dp
//import com.example.text.ui.mall.model.Image
//
////import com.jczy.cyclone.R
////import com.jczy.cyclone.app.dp
////import com.jczy.cyclone.databinding.ItemNinePicPreviewMallBinding
////import com.jczy.cyclone.model.Image
////import com.jczy.cyclone.ui.mall.adapter.EvaluationListMultiAdapter
////import com.jczy.cyclone.utils.glide.GlideApp
////import com.jczy.lib_utils.ToastUtils
//
//
///**
// *@author Wcj
// *@description
// *@date 2022/7/5 15:42
// */
//class EvaluationNinePicsAdapter(private val itemType: Int, private val picItems: List<Image>, private val imageClick: (Int) -> Unit) :
//    RecyclerView.Adapter<EvaluationNinePicsAdapter.PicViewHolder>() {
//
//    private lateinit var context: Context
//
//    override fun getItemViewType(position: Int): Int {
//        return if (picItems.isEmpty()) {
//            NONE.value
//        } else {
//            NINE.value
//        }
//    }
//
//    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PicViewHolder {
//        context = parent.context
//        val binding = ItemNinePicPreviewMallBinding.inflate(LayoutInflater.from(parent.context))
//        val imageView = binding.root as ViewGroup
////        val imageView = ImageView(context).apply {
////            scaleType = ImageView.ScaleType.CENTER_CROP
////            foreground = context.getDrawable(R.drawable.shape_bg_normal_ripple_with_round_mask)
////        }
//        when (viewType) {
//            NINE.value -> {
//                return when (itemType) {
//                    EvaluationListMultiAdapter.TYPE_1V1P -> {
//                        PicViewHolder(binding, 110.dp, 110.dp)
//                    }
//                    EvaluationListMultiAdapter.TYPE_1V2P -> {
//                        PicViewHolder(binding, 67.dp, 67.dp)
//                    }
//                    EvaluationListMultiAdapter.TYPE_0V4P -> {
//                        PicViewHolder(binding, 76.dp - 1, 76.dp - 1, margin = 2)
//                    }
//                    EvaluationListMultiAdapter.TYPE_AFTER_DETAIL -> {
//                        PicViewHolder(binding, 46.dp, 46.dp, margin = 5.dp)
//                    }
//
//                    else -> PicViewHolder(binding, 112.dp, 112.dp)
//                }
//            }
//        }
//        return PicViewHolder(binding, 112.dp, 112.dp)
//    }
//
//    override fun onBindViewHolder(holder: PicViewHolder, position: Int) {
//
//        val ifVideo = picItems[position].url.endsWith(".mp4")
//        var thumbnailUrl = picItems[position].run {
//            if (ifVideo){
//                this.url
//            } else {
//                this.thumbnailUrl?.ifEmpty { this.url }?: this.url
//            }
//        }
//        if (ifVideo)
//            thumbnailUrl = "${thumbnailUrl}?x-oss-process=video/snapshot,t_75,m_fast"
//
//        holder.apply {
//            ivPlay.visibility = if (ifVideo) View.VISIBLE else View.GONE
//
//            val req = GlideApp.with(itemView.context)
//                .asBitmap()
//                .load(thumbnailUrl)
////                .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
//                .listener(object : RequestListener<Bitmap> {
//                    override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Bitmap>?, isFirstResource: Boolean): Boolean {
//                        itemView.setOnClickListener {
//                            ToastUtils.showShort(context, context.getString(R.string.string_image_error))
//                        }
//                        return false
//                    }
//
//                    override fun onResourceReady(
//                        resource: Bitmap?,
//                        model: Any?,
//                        target: Target<Bitmap>?,
//                        dataSource: DataSource?,
//                        isFirstResource: Boolean
//                    ): Boolean {
//                        itemView.setOnClickListener {
//                            imageClick.invoke(holder.absoluteAdapterPosition)
//                        }
//                        return false
//                    }
//                }).dontAnimate()
//            // 售后凭证需要加圆角
//            if (itemType == EvaluationListMultiAdapter.TYPE_AFTER_DETAIL) {
//                req.placeholder(R.drawable.shape_bg_f8f8f8_round_4dp)
//                    .error(R.drawable.shape_bg_f8f8f8_round_4dp)
//                    .apply(RequestOptions().transform(CenterCrop(), RoundedCorners(9.dp)))
//            }
//            // req.into(itemView as ImageView)
//            req.into(holder.ivPic)
//        }
//    }
//
//    override fun getItemCount(): Int = picItems.size
//
//    inner class PicViewHolder(binding: ItemNinePicPreviewMallBinding, width: Int, height: Int, margin: Int = 1.dp) : RecyclerView.ViewHolder(binding.root) {
//        val ivPic: ImageView = binding.ivPic
//        val ivPlay: ImageView = binding.ivPlay
//
//        init {
//            val lp = ViewGroup.MarginLayoutParams(width, height)
//            lp.setMargins(margin, margin, margin, margin)
//            binding.root.layoutParams = lp
//        }
//    }
//}